package com.yf.tz.service.impl;

import com.yf.response.RRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.yf.tz.dao.MallAddressDao;
import com.yf.tz.entity.MallAddressEntity;
import com.yf.tz.service.MallAddressService;
import com.yf.service.impl.BaseServiceImpl;

/**
 * 商城地址Service实现类
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Mon Jul 20 09:44:30 CST 2020
 */
@Service
public class MallAddressServiceImpl extends BaseServiceImpl<MallAddressEntity> implements MallAddressService {

    private MallAddressDao mallAddressDao;


    @Autowired
    public void setDao(MallAddressDao mallAddressDao) {
        this.mallAddressDao = mallAddressDao;
        super.setBaseDao(mallAddressDao);
    }


    /**
     *
     *
     @Override
     List<MallAddressVo> queryListVo(MallAddressVo mallAddressVo){
            return mallAddressDao.queryListVo(mallAddressVo);
     }

     @Override
     MallAddressVo getVo(Long id){
                return mallAddressDao.getVo(id);
    }

     **/


    /**内部方法**/



    /**外部方法实现**/

    @Override
    public MallAddressEntity merge(Long userId,MallAddressEntity addressEntity) {
        if(addressEntity.getId()==null){
            addressEntity.setUserId(userId);
            mallAddressDao.save(addressEntity);
        }else {
            if(!userId.equals(addressEntity.getUserId())){
                throw new RRException("数据异常");
            }
            if(addressEntity.getDef()!=null&&addressEntity.getDef()==true){ // 如果当前是默认 设置其他为非默认
                mallAddressDao.updateByDef(false);
            }
            mallAddressDao.update(addressEntity);
        }
        return addressEntity;
    }

    @Override
    public List<MallAddressEntity> findByUserId(Long userId) {
        return mallAddressDao.findByUserId(userId);
    }
}
